const {
  request
} = require("../../utils/index.js")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item:Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    artId:"",  //帖子id
    word:true,  //文字展开
    inputValue:"",
  },
  ready(){
    this.setData({
      artId:this.data.item.artId
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //文字展开或收起
    word:function(){
      this.setData({
        word: !this.data.word
    })
    },
    // 点击查看图片
    handleSwiper(e){
      let {url} = e.currentTarget.dataset;
      let pics = this.data.item.files.map(v=>v.updUrl);
      wx.previewImage({
        current:url,
        urls: pics,
      })
    },
      // 视频展示
  chooseshow: function (e) {
    var that = this;
    console.log(that.data.item)
    wx.previewMedia({
      current: 0,
      type: 'video',
      url: that.data.item.files[0].updUrl
    })
  },
    //精英分享点赞增加
    fxdianzan:async function(e){
      let param={
       url:"hw/portal/user/praise/save",
       header:{
        'content-type': 'application/x-www-form-urlencoded', // 默认值
       },
       data:{
        "token":wx.getStorageSync('token'),
        "praiseModule":"daily_share",
        "objId":this.data.artId,
       },
       method:"POST"
      }
      let res=await request(param);
      if(res.status==100){
        this.setData({
          "item.isPraise":!this.data.item.isPraise,
          "item.praiseCount":++this.data.item.praiseCount
        })
      }
    },
    //精英分享点赞取消
    fxcanceldianzan:async function(){
      let param={
        url:"hw/portal/user/praise/del",
        header:{
         'content-type': 'application/x-www-form-urlencoded', // 默认值
        },
        data:{
         "token":wx.getStorageSync('token'),
         "praiseModule":"daily_share",
         "objId":this.data.artId,     //当前用户id
        },
        method:"POST"
       }
       let res=await request(param);
       if(res.status==100){
         this.setData({
           "item.isPraise":!this.data.item.isPraise,
           "item.praiseCount":--this.data.item.praiseCount
         })
       }
    },
    //评论点赞增加
    PLdianzan:async function(e){
      let dataset=e.currentTarget.dataset;
      let param={
       url:"hw/portal/user/praise/save",
       header:{
        'content-type': 'application/x-www-form-urlencoded', // 默认值
       },
       //
       data:{
        "token":wx.getStorageSync('token'),
        "praiseModule":"comment",
        "objId":e.currentTarget.dataset.cmtid,
       },
       method:"POST"
      }
      let res=await request(param);
      //点赞数量+1
      if(res.status==100){
        let arrCut = 'item.comments['+dataset.index+'].isPraise';
        let praiseCount='item.comments['+dataset.index+'].praiseCount';
        let value=
         this.setData({
           [arrCut]:!this.data.item.comments[dataset.index].isPraise,
           [praiseCount]:++this.data.item.comments[dataset.index].praiseCount
         })
      }
    },
    //评论点赞取消
    PLcanceldianzan:async function(){
      let param={
        url:"hw/portal/user/praise/del",
        header:{
         'content-type': 'application/x-www-form-urlencoded', // 默认值
        },
        data:{
         "token":wx.getStorageSync('token'),
         "praiseModule":"comment",
         "objId":this.data.artId, 
        },
        method:"POST"
       }
       let res=await request(param);
       if(res.status==100){
         this.setData({
           "item.isPraise":!this.data.item.isPraise,
           "item.isCollect":--this.data.item.isCollect
         })
       }
       console.log(this.data.item.visitsCount)
    },
    //精英分享收藏增加
    fxshoucang:async function(e){
      let param={
       url:"hw/portal/user/collect/save",
       header:{
        'content-type': 'application/x-www-form-urlencoded', // 默认值
       },
       data:{
         "token":wx.getStorageSync('token'),
        "collectModule":"daily_share",
        "objId":this.data.item.artId,
       },
       method:"POST"
      }
      let datainfo=await request(param);
      if(datainfo.status==100){
        this.setData({
          "item.isCollect":!this.data.item.isCollect,
          "item.collectCount":++this.data.item.collectCount
        })
      }
    },
    //精英分享收藏取消
    fxcanceshoucang:async function(){
      let parm={
        url:"hw/portal/user/collect/del",
        header:{
         'content-type': 'application/x-www-form-urlencoded', // 默认值
        },
        data:{
         "token":wx.getStorageSync('token'),
         "collectModule":"daily_share",
         "objId":this.data.artId,     //当前用户id
        },
        method:"POST"
       }
       let datainfo =await request(parm);
       if(datainfo.status==100){
         this.setData({
          "item.isCollect":!this.data.item.isCollect,
          "item.collectCount":--this.data.item.collectCount
         })
       }
    },

    //进入详情页
    getshareinfo(){
      wx.navigateTo({
        url:'../../pages/sharetent/sharetent?artId='+this.data.artId
      })
    },
  }
})
